package com.baizhi.springboot.service.impl;

import com.baizhi.springboot.dao.BannerDao;
import com.baizhi.springboot.entity.Banner;
import com.baizhi.springboot.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Transactional
@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerDao bannerDao;
    @Override
    @Transactional(readOnly = true)
    public Map<Object, Object> selectBannerByPage(Integer page, Integer limit) {

        Integer offset=(page-1)*limit;
        List<Banner> banners = bannerDao.selectBannerByPage(offset, limit);
        Integer count = bannerDao.selectCount();
        /* "code": 0,
          "msg": "",
          "count": 1000,
          "data": [{}, {}]*/
        HashMap<Object, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", banners);
        return map;
    }

    @Override
    public void insertBanner(Banner banner) {
        bannerDao.insertBanner(banner);
    }

    @Override
    public void deleteBanner(Integer id) {
        bannerDao.deleteBanner(id);

    }

    @Override
    public Banner selectOneBanner(Integer id) {
        return bannerDao.selectOneBanner(id);
    }

    @Override
    public void updateBanner(Banner banner) {
        bannerDao.updateBanner(banner);
    }
}
